package com.sms.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sms.common.A;
import com.sms.pojo.FundsType;
import com.sms.service.impl.FundsTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//资金类型列表
@WebServlet("/FundsTypeList")
public class FundsTypeListController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String _pageIndex=req.getParameter("pageIndex");
        String _pageSize=req.getParameter("pageSize");
        Integer pageIndex= StrUtil.isNotEmpty(_pageIndex)?Integer.parseInt(_pageIndex):1;
        Integer pageSize=StrUtil.isNotEmpty(_pageSize)?Integer.parseInt(_pageSize):10;

        String orderBy=req.getParameter("orderBy");

        FundsTypeServiceImpl service=new FundsTypeServiceImpl();
        if(StrUtil.isNotEmpty(orderBy)){
            PageHelper.startPage(pageIndex,pageSize,orderBy);
        }else{
            PageHelper.startPage(pageIndex,pageSize);
        }
        List<FundsType> list = service.listFundsType();

        PageInfo<FundsType> pageInfo=new PageInfo<>(list);
        resp.getWriter().write(JSONUtil.toJsonStr(A.success("资金类型查询成功",pageInfo)));

    }
}
